<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>test</title>
        <style>
            .navbar {
                display: flex;
                background-color: #c0392b;
                align-items: center;
                padding: 10px;
            }

            .navbar a {
                color: #fff;
                padding: 14px 20px;
                text-decoration: none;
                text-align: center;
            }
    z
            .navbar a:hover {
                background-color: #ddd;
                color: black;
            }

            /* Logo 和网站名称样式 */
            .logo-container {
                display: flex;
                align-items: center;
                margin-right: auto; /* 将其他导航项推到右侧 */
            }

            .logo-container img {
                height: 40px; /* 根据需要调整图像高度 */
                margin-right: 10px;
            }

            .logo-container span {
                color: #fff;
                font-size: 24px; /* 根据需要调整字体大小 */
            }

            /* 下拉菜单样式 */
            .dropdown {
                position: relative;
                display: inline-block;
            }

            .dropdown-content {
                display: none;
                position: absolute;
                background-color: #f9f9f9;
                min-width: 160px;
                z-index: 1;
            }

            .dropdown-content a {
                color: black;
                padding: 12px 16px;
                text-decoration: none;
                display: block;
            }

            .dropdown-content a:hover {
                background-color: #f1f1f1;
            }

            .dropdown:hover .dropdown-content {
                display: block;
            }

            .dropdown:hover .dropbtn {
                background-color: #ddd;
                color: black;
            }


.modal {
            display: none;
            position: fixed;
            top: 0;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(255, 255, 255, 0.9);
            padding: 20px;
            border: 2px solid black;
            z-index: 20;
            text-align: center;
            width: 300px;
            animation:  fadeIn 0.5s, fadeOut 1s 2s forwards;
}
@keyframes shake {
        0% { transform: translate(-50%, -50%) translateX(0); }
        25% { transform: translate(-50%, -50%) translateX(-10px); }
        50% { transform: translate(-50%, -50%) translateX(10px); }
        75% { transform: translate(-50%, -50%) translateX(-10px); }
        100% { transform: translate(-50%, -50%) translateX(0); }
    }

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

#easterEggModal  {
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.popup {
    display: none;
    position: fixed;
    z-index: 1;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border: 2px solid black;
    text-align: center;
    width: 300px;
}

.qrcode {
    width: 100%;
    height: auto;
}

.popup button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

        </style>
    </head>
    <body>

        <div class="navbar">
            <div class="logo-container">
                <img src="img/logo.png" alt="Logo">
                <span>福卫兵</span>
            </div>
            <a href="#">主页</a>
            <div class="dropdown">
                <a href="#" class="dropbtn">菜单</a>
                <div class="dropdown-content">
                    <a href="index.html">图片分析</a>
                    <a href="comment_analyse.html">贴吧评论分析</a>
					<a href="analyse_demo.html">微博评论分析</a>
                </div>
            </div>

<a id="aboutButton">关于我们</a>
    <a id="contactButton">联系</a>
</div>
<div id="aboutModal" class="modal">
        <p>大数据福卫兵兵团感谢你的喜欢</p>
</div>

<div id="easterEggModal" class="modal">
        <p>维护福大网络环境 人人有责 快来加入福卫兵吧</p>
</div>

<div id="contactModal" class="popup">
    <img src="img/qrcode.png" alt="QR Code" class="qrcode">
    <button onclick="closeContactModal()">×</button>
</div>
    </body>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据展示页面</title>
    <link rel="stylesheet" href="/css/styles.css">
    <!-- 引入 Chart.js 和插件 -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <style>



        body {
            font-family: "微软雅黑", Arial, sans-serif;
            background-color: #f8e9e9;
            color: #333;
            margin: 0;
            padding: 0;
        }

        header {
            background-color: #f8e9e9;
            padding: 20px;
            text-align: center;
            color: white;
        }

        header h1 {
            margin: 0;
            font-size: 36px;
            color: #c0392b;
        }



        main {
            max-width: 1500px;
    margin: 20px auto;
    padding: 0 20px;
    display: grid;
    grid-template-rows: 650px auto;
    grid-template-columns: 400px auto  400px; /* 假设左右侧边栏各200px宽，中间自适应 */
    grid-template-areas:
        "left chart right"
        "normal normal normal";
        }
.left-sidebar {
    grid-area: left;
    background-color: #f8e9e9;
    padding: 10px;
    box-shadow: 0 4px 8px rgba(192, 57, 43, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.right-sidebar {
    grid-area: right;
    background-color: #f8e9e9;
    padding: 10px;
    box-shadow: 0 4px 8px rgba(192, 57, 43, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.player {
    margin-top: 10px;
    height: 300px;
    width: 400px;
    background-color: rgba(216, 218, 221, 0.5);
    border-radius: 10px;
}


        .cover {
    height: 200px;
    width: 400px;
    margin-left: 20px;
    margin-top: 15px;
    overflow: hidden;
    border-radius: 10px;
    display: flex;
    /* 水平方向布局，两端对齐 */
    justify-content: flex-start;
    /* 垂直方向居中对齐 */
    align-items: stretch;
}

.right-sidebar audio {
    width: 100%;
    height: 30px; /* 适当调整高度，可根据实际情况修改 */
    border-radius: 10px;
}
.song {
         margin-bottom: 50px;
    margin-left: 10px;
    font-family: "楷体" ;
}
.player h2{
    font-family: "楷体";
    margin: 10px;
    margin-left: 50px;
}

.music-back {
    width: 200px;
    height: auto;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
audio {
    width: 100%; /* 宽度为100% */
    height: 50px; /* 高度为50px */
    border-radius: 10px; /* 边框半径为10px */
}

/* 设置音频播放进度条的颜色 */
audio::-webkit-media-controls-progress-bar {
    background-color: #000;
}

/* 定义播放器的背景颜色 */
.player {
    /* background: linear-gradient(to bottom, #304352, #d7d2cc); */
    background-color: rgba(238, 238, 238, 0.2); /* 背景颜色为rgba(238, 238, 238, 0.2) */
}

/* 隐藏音频播放器的背景颜色 */
audio::-webkit-media-controls-enclosure {
    background-color: rgba(216, 218, 221, 0.0);
}
        .chart-container {
            grid-area: chart;
    background-color: white;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(192, 57, 43, 0.2);
    height: 600px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
        }

        .chart-container canvas, .chart-container #wordCloud {
            width: 100% !important;
            height: 100% !important;
        }

        /* 翻页按钮样式 */
        .chart-pagination {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 100%;
            display: flex;
            justify-content: space-between;
            padding: 0 10px;
        }

        .chart-pagination button {
            background-color: transparent;
            border: none;
            cursor: pointer;
            padding: 0;
            width: 40px;
            height: 40px;
        }

        .chart-pagination button img {
            width: 100%;
            height: 100%;
            object-fit: contain;
            transition: transform 0.2s;
        }

        .chart-pagination button:hover img {
            transform: scale(1.1);
        }

        form {
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 20px 0;
        }

        input[type="file"] {
            margin-right: 10px;
            border: none;
            padding: 10px 20px;
            font-size: 14px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button.submit-button {
            background-color: #c0392b;
            color: white;
            border: none;
            padding: 10px 20px;
            font-size: 14px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button.submit-button:hover {
            background-color: #a93226;
        }

        table {
            grid-area: normal;
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
        }

        th, td {
            padding: 15px;
            text-align: center;
            border-bottom: 1px solid #f2f2f2;
            color: #333;
            min-width: 100px;
        }

        th {
            background-color: #c0392b;
            color: white;
            font-weight: bold;
        }

        tr:hover td {
            background-color: #fbeeea;
            border-radius: 5px;
            transition: background-color 0.2s, border-radius 0.2s;
        }

        img {
            cursor: pointer;
            width: 80px;
            height: auto;
            border-radius: 5px;
            transition: transform 0.2s;
        }

        img:hover {
            transform: scale(1.1);
        }

        .emotion-chart {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 200px;
        }

        .emotion-chart canvas {
            width: 200px ;
            height: 200px ;
        }

        .pagination {
            grid-area: normal;
    display: flex;
    justify-content: center;
    align-items: flex-end;
	margin-bottom: -5%;
        }

        .pagination button {
            background-color: #c0392b;
            color: white;
            border: none;
            padding: 10px 15px;
            font-size: 14px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin: 0 5px;
        }

        .pagination button:hover {
            background-color: #a93226;
        }

        .pagination button:disabled {
            background-color: #d98880;
            cursor: not-allowed;
        }

        .pagination input {
            text-align: center;
            padding: 10px;
            font-size: 14px;
            border: 1px solid #ccc;
            border-radius: 5px;
            transition: border-color 0.3s;
            margin-left: 10px;
            width: 60px;
        }

        .pagination input:focus {
            border-color: #c0392b;
            outline: none;
        }

        @media screen and (max-width: 768px) {
            .emotion-chart canvas {
                width: 150px !important;
                height: 150px !important;
            }

            img {
                width: 80px;
            }

            th, td {
                padding: 10px;
            }
        }

            .wordcloud  {
                width: 100%;
                height: 90%;

            }
			.word{
				margin: 0;
				font-size: 30px;
				font-weight: bold;
				color: #c0392b;
				text-align: center;
			}
            @keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.music-back.rotating {
    animation: rotate 2s linear infinite;
}
.ai-window {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 100%;
    height: 700px;
    position: relative;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    border-radius: 10px;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
    background: url('img/aibg.jpg') no-repeat center center; /* Add your background image here */
    background-size: cover;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#chatContainer {
    overflow-y: auto;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    margin-top: auto;
    padding: 10px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.1);
}

.sent-message, .reply-message {
    width: fit-content;
    max-width: 80%;
    padding: 10px 15px;
    margin: 5px 0;
    border-radius: 20px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sent-message {
    align-self: flex-end;
    background-color: #c0392b;
    color: #fff;
}

.reply-message {
    align-self: flex-start;
    background-color: #ecf0f1;
    color: #333;
}

#userInput {
    width: calc(100% - 40px);
    padding: 10px;
    margin-top: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 16px;
}
.button-container {
    position: relative;
    z-index: 10; /* 保持按钮容器较高的层级 */
    text-align: center; /* 使按钮在水平方向居中 */
    margin-bottom: -10px;
    margin-top: -20px;

}
.clickable-image {
    display: inline-block;
    cursor: pointer;
    transition: transform 0.3s;
}

.clickable-image:hover {
    transform: scale(1.1); /* Slightly enlarge the image on hover */
}


@keyframes fadeIn {
    from {
        opacity: 0; /* 初始透明度为0，完全透明 */
    }
    to {
        opacity: 1; /* 最终透明度为1，完全显示 */
    }
}
img {
            cursor: pointer;
            width: 80px;
            height: auto;
            border-radius: 5px;
            transition: transform 0.2s;
        }

        img:hover {
            transform: scale(1.1);
        }
.calendar-container {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    width: 100%;
    max-width: 400px;
    background-color: #fff;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.calendar-day {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    position: relative; /* Add this line */
}
.calendar-day.today {
    background-color: #77fffa;
}

.calendar-day.marked {
    background-color: #fa8377;
    color: #fff;
}

.calendar-container button {
    background-color: #c0392b;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin: 0 10px;
}

.calendar-container button:hover {
    background-color: #a93226;
}
.stamp {
    position: absolute;
    width: 30px;
    height: 30px;
    bottom: 5px;
    right: 5px;
    animation: stampAnimation 1s forwards;
}

@keyframes stampAnimation {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(20deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}
.small-stamp {
   position: absolute;
    width: 20px;
    height: 20px;
    bottom: 0;
    right: -3px;
    z-index: 10;
}
    </style>
</head>

<body>
    <header>
        <h1>福卫兵is all you need</h1>
        <h1>福卫兵出击</h1>
    </header>

   <main>
    <!-- Update the HTML in templates/data.html -->
    <div class="chart-container">
        <canvas id="barChart" ></canvas>
        <div id="wordCloud" style="display: none;">
            <p class="word">Fzuer都说了什么呢</p>
            <img src="img/wordcloud.png" alt="Word Cloud" class="wordcloud">
        </div>
        <div class="chart-pagination">
            <button id="prevChart" title="上一页">
                <img src="img/back-icon.png" alt="上一页">
            </button>
            <button id="nextChart" title="下一页">
                <img src="img/skip.png" alt="下一页">
            </button>
        </div>
    </div>

  <div class="left-sidebar">
      <div class="ai-window">
      <div id="chatContainer"></div>
      <input type="text" id="userInput" placeholder="福兵，开启今日的巡查吧！">
  </div>
  <div class="button-container">
      <img src="img/fu.png" alt="Clickable Image" class="clickable-image" onclick="sendText()">
  </div>


  </div>


    <div class="right-sidebar">
        <!-- 音乐播放器 -->
        <div class="player">
            <!-- 歌曲封面 -->
            <div class="cover">
                <img src="music/back.jpg" alt="" class="music-back">
                <div class="song">
                    <p>
                    纯音乐,请欣赏<br>
                    </p>
                </div>
            </div>
            <!-- 歌词设置 -->
            <h2>清澈的眼睛</h2>
            <!-- audio标签 -->
            <div class="mus">
                <audio src="music/bgm.mp3" controls autoplay loop></audio>
            </div>
        </div>
		<div class="calendar-container">
		    <div id="calendar"></div>
		</div>
    </div>

    <table>
        <thead>
            <tr>
                <th>序号</th>
                <th>昵称</th>
                <th>内容</th>
                <th>情感</th>
            </tr>
        </thead>
        <tbody id="commentsTableBody"></tbody>
    </table>

    <div class="pagination">
        <button id="prevPage" disabled>上一页</button>
        <span id="pageInfo"></span>
        <button id="nextPage">下一页</button>
        <input type=" number" id="jumpToPage" min="1" placeholder="页码">
        <button id="jumpPageButton">跳转</button>
    </div>
</main>

    <script>
		document.addEventListener('DOMContentLoaded', function () {
		    const calendar = document.getElementById('calendar');
		    const today = new Date();
		    const year = today.getFullYear();
		    const month = today.getMonth();
		    const date = today.getDate();
		    let isStamped = false; // Flag to track if the stamp has been applied

		    function generateCalendar(year, month) {
		        calendar.innerHTML = '';
		        const firstDay = new Date(year, month, 1).getDay();
		        const daysInMonth = new Date(year, month + 1, 0).getDate();

		        for (let i = 0; i < firstDay; i++) {
		            const emptyCell = document.createElement('div');
		            calendar.appendChild(emptyCell);
		        }

		        for (let day = 1; day <= daysInMonth; day++) {
		            const dayCell = document.createElement('div');
		            dayCell.textContent = day;
		            dayCell.classList.add('calendar-day');
		            if (day === date) {
		                dayCell.classList.add('today');
		            }
		            calendar.appendChild(dayCell);
		        }
		    }

		    generateCalendar(year, month);

		    const clickableImage = document.querySelector('.clickable-image');
		    clickableImage.addEventListener('click', function () {
		        if (!isStamped) { // Check if the stamp has already been applied
		            const todayCell = document.querySelector('.calendar-day.today');
		            if (todayCell) {
		                const stamp = document.createElement('img');
		                stamp.src = 'img/fu.png';
		                stamp.classList.add('stamp');
		                todayCell.appendChild(stamp);

		                setTimeout(() => {
		                    todayCell.classList.add('marked');
		                    stamp.remove();

		                    const smallImage = document.createElement('img');
		                    smallImage.src = 'img/fu.png'; // Path to the small image
		                    smallImage.classList.add('small-stamp');
		                    todayCell.appendChild(smallImage);
		                }, 1000); // Adjust the timeout duration as needed

		                isStamped = true; // Set the flag to true after stamping
		            }
		        }
		    });
		});
        function handleKeyPress(event) {
            if (event.key === 'Enter') {
                sendText();
            }
        }
        function sendText() {
            const userInput = document.getElementById('userInput').value.trim();
            const chatContainer = document.getElementById('chatContainer');
        
            if (userInput !== '') {
                // 显示用户发送的消息
                const userMessage = document.createElement('div');
                userMessage.textContent = userInput;
                userMessage.classList.add('sent-message');
                chatContainer.appendChild(userMessage);
        
                // 清空输入框
                document.getElementById('userInput').value = '';
        
                // 滚动到聊天底部
                chatContainer.scrollTop = chatContainer.scrollHeight;
        
                // 发送请求到后端处理
                fetch('http://localhost:5000/api/chat', { // 请根据实际后端地址修改
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ message: userInput })
                })
                .then(response => response.json())
                .then(data => {
                    // 显示 AI 助手的回复
                    const aiMessage = document.createElement('div');
                    aiMessage.textContent = data.reply; // 假设后端返回 { reply: "回复内容" }
                    aiMessage.classList.add('reply-message');
                    chatContainer.appendChild(aiMessage);
        
                    // 滚动到聊天底部
                    chatContainer.scrollTop = chatContainer.scrollHeight;
                })
                .catch(error => {
                    console.error('Error:', error);
                    const errorMessage = document.createElement('div');
                    errorMessage.textContent = '抱歉，出现了一个错误。请稍后再试。';
                    errorMessage.classList.add('reply-message');
                    chatContainer.appendChild(errorMessage);
                    chatContainer.scrollTop = chatContainer.scrollHeight;
                });
            }
        }
        function showMessage() {
            $('#message').show();
            $('#message').css('animation-play-state', 'running'); // 触发动画开始播放
        
        }

        document.addEventListener('DOMContentLoaded', function () {
    const audio = document.querySelector('audio');
    const musicImg = document.querySelector('.music-img');

    function toggleRotation() {
        if (audio.paused) {
            musicImg.classList.remove('rotating');
        } else {
            musicImg.classList.add('rotating');
        }
    }

    audio.addEventListener('play', toggleRotation);
    audio.addEventListener('pause', toggleRotation);
    audio.addEventListener('ended', toggleRotation);

    // Start rotation if audio is already playing (autoplay)
    if (!audio.paused) {
        musicImg.classList.add('rotating');
    }
});
document.addEventListener('DOMContentLoaded', function () {
    let aboutClickCount = 0;

const aboutModal = document.getElementById('aboutModal');
const easterEggModal = document.getElementById('easterEggModal');
const contactModal = document.getElementById('contactModal');

const aboutButton = document.getElementById('aboutButton');
const contactButton = document.getElementById('contactButton');

aboutButton.addEventListener('click', function () {
    aboutClickCount++;
    aboutModal.style.display = 'block';
    setTimeout(function () {
        aboutModal.style.display = 'none';
    }, 5000); // 5 seconds total (0.5s fade in + 2s fade out + 2.5s display time)

    if (aboutClickCount % 10 === 0) {
        easterEggModal.style.display = 'block';
        setTimeout(function () {
            easterEggModal.style.display = 'none';
        }, 5000); // 5 seconds display time
    }
});

contactButton.addEventListener('click', function () {
    contactModal.style.display = 'block';
    setTimeout(function () {
        contactModal.style.display = 'none';
    }, 5000); // 5 seconds display time
});

window.addEventListener('click', function (event) {
    if (event.target === aboutModal) {
        aboutModal.style.display = 'none';
    }
    if (event.target === easterEggModal) {
        easterEggModal.style.display = 'none';
    }
    if (event.target === contactModal) {
        contactModal.style.display = 'none';
    }
});
    let currentPage = 1;
    const itemsPerPage = 10;
    let data = [];

    fetch('http://127.0.0.1:5000/api/comments')

    .then(response => {
        if (!response.ok) {
            throw new Error(`HTTP 错误! 状态: ${response.status}`);
        }
        return response.json();
    })
    .then(jsonData => {
        if (jsonData.comments) {
            data = jsonData.comments;
            renderTable(currentPage);
            renderBarChart(); // 确保数据加载后绘制柱形图
        } else {
            console.error('No comments data found.');
        }
    })
    .catch(error => {
        console.error('Error fetching data:', error);
    });

    function renderTable(page) {
        const tableBody = document.getElementById('commentsTableBody');
        tableBody.innerHTML = '';

        const start = (page - 1) * itemsPerPage;
        const end = start + itemsPerPage;
        const pageData = data.slice(start, end);

        console.log(`Rendering page ${page} data:`, pageData); // 调试用


        pageData.forEach(comment => {
            const row = document.createElement('tr');
        // 显示 id
            const idCell = document.createElement('td');
            idCell.textContent = comment.id;
            row.appendChild(idCell);
        // 显示昵称
            const nicknameCell = document.createElement('td');
            nicknameCell.textContent = comment.nickname;
            row.appendChild(nicknameCell);
        // 显示内容
            const contentCell = document.createElement('td');
            contentCell.textContent = comment.content;
            row.appendChild(contentCell);

        // 显示情感分析为饼图
        const sentimentCell = document.createElement('td');
        const canvas = document.createElement('canvas');
        canvas.width = 250; // 设置饼图宽度
        canvas.height = 250; // 设置饼图高度
        sentimentCell.appendChild(canvas);
        row.appendChild(sentimentCell);

        tableBody.appendChild(row);

        // 准备饼图数据
        const emotions = Object.keys(comment.sentiment);
        const values = Object.values(comment.sentiment);

        // 生成随机颜色
        const backgroundColors = emotions.map(() => `rgba(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, 0.6)`);

        // 创建饼图
        new Chart(canvas.getContext('2d'), {
            type: 'pie',
            data: {
                labels: emotions,
                datasets: [{
                    data: values,
                    backgroundColor: backgroundColors,
                    borderColor: 'rgba(255, 255, 255, 1)',
                    borderWidth: 1
                }]
            },
            options: {
                responsive: false,
                plugins: {
                    legend: {
                        position: 'bottom',
                        labels: {
                            font: {
                                size: 10
                            }
                        }
                    },
                    tooltip: {
                        callbacks: {
                            label: function(context) {
                                const label = context.label || '';
                                const value = context.parsed || 0;
                                return `${label}: ${value}`;
                            }
                        }
                    }
                }
            }
        });



        });
            // 计算总页数
    const totalPages = Math.ceil(data.length / itemsPerPage);
    document.getElementById('pageInfo').textContent = `第 ${page} 页，共 ${totalPages} 页`;

    // 更新分页按钮状态
    document.getElementById('prevPage').disabled = page === 1;
    document.getElementById('nextPage').disabled = page === totalPages;

    }
    function renderBarChart() {
        const ctx = document.getElementById('barChart').getContext('2d');
        const emotionLabels = ['愤怒', '厌恶', '恐惧', '喜悦', '悲伤', '惊讶', '中性'];
        const emotionTotals = {
            '愤怒': 0,
            '厌恶': 0,
            '恐惧': 0,
            '喜悦': 0,
            '悲伤': 0,
            '惊讶': 0,
            '中性': 0
        };

        data.forEach(item => {
            let maxEmotion = '中性';
            let maxValue = 0;
            for (let emotion in item.sentiment) {
                if (item.sentiment[emotion] > maxValue) {
                    maxValue = item.sentiment[emotion];
                    maxEmotion = emotion;
                }
            }
            emotionTotals[maxEmotion]++;
        });

        const emotionValues = Object.values(emotionTotals);

        new Chart(ctx, {
            type: 'bar',
            data: {
                labels: emotionLabels,
                datasets: [{
                    label: '情绪总结',
                    data: emotionValues,
                    backgroundColor: [
                        '#c0392b',
                        '#a93226',
                        '#e67e22',
                        '#f1c40f',
                        '#3498db',
                        '#9b59b6',
                        '#95a5a6'
                    ],
                    borderColor: [
                        '#c0392b',
                        '#a93226',
                        '#e67e22',
                        '#f1c40f',
                        '#3498db',
                        '#9b59b6',
                        '#95a5a6'
                    ],
                    borderWidth: 1
                }]
            },
            options: {
                responsive: true,
                scales: {
                    y: {
                        beginAtZero: true,
                        ticks: {
                            precision: 0,
                            font: {
                                size: 14
                            },
                            callback: function(value) {
                                if (Number.isInteger(value)) {
                                    return value;
                                }
                            }
                        },
                        grid: {
                            display: false
                        }
                    },
                    x: {
                        ticks: {
                            font: {
                                size: 14
                            }
                        },
                        grid: {
                            display: false
                        }
                    }
                },
                plugins: {
                    datalabels: {
                        anchor: 'end',
                        align: 'end',
                        offset: -10,
                        color: '#333',
                        font: {
                            size: 14,
                            weight: 'bold'
                        },
                        formatter: function(value) {
                            return Math.round(value);
                        }
                    }
                }
            },
            plugins: [ChartDataLabels]
        });
    }

    document.getElementById('prevPage').addEventListener('click', function () {
        if (currentPage > 1) {
            currentPage--;
            renderTable(currentPage);
        }
    });

    document.getElementById('nextPage').addEventListener('click', function () {
        if ((currentPage * itemsPerPage) < data.length) {
            currentPage++;
            renderTable(currentPage);
        }
    });

    document.getElementById('jumpPageButton').addEventListener('click', function () {
        const jumpToPage = parseInt(document.getElementById('jumpToPage').value);
        if (jumpToPage > 0 && jumpToPage <= Math.ceil(data.length / itemsPerPage)) {
            currentPage = jumpToPage;
            renderTable(currentPage);
        }
    });
});

            // 图表翻页功能
            document.getElementById('prevChart').addEventListener('click', function () {
                if (currentChart === 'bar') {
                    currentChart = 'wordCloud';
                } else {
                    currentChart = 'bar';
                }
                toggleChart();
            });

            document.getElementById('nextChart').addEventListener('click', function () {
                if (currentChart === 'wordCloud') {
                    currentChart = 'bar';
                } else {
                    currentChart = 'wordCloud';
                }
                toggleChart();
            });

            function toggleChart() {
                if (currentChart === 'bar') {
                    document.getElementById('barChart').style.display = 'block';
                    document.getElementById('wordCloud').style.display = 'none';
                } else {
                    document.getElementById('barChart').style.display = 'none';
                    document.getElementById('wordCloud').style.display = 'block';
                }
            }

             
    </script>
</body>
</html>